package com.sdu.cloudservice.service.impl;

import com.sdu.cloudservice.dao.ConfigInfoDao;
import com.sdu.cloudservice.dao.InstanceInfoDao;
import com.sdu.cloudservice.dto.Envelope;
import com.sdu.cloudservice.service.InstanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Create by zekdot on 19-6-24.
 * @author
 * ZMX
 */
@Service
public class InstanceServiceImpl implements InstanceService {

    @Autowired
    private InstanceInfoDao instanceInfoDao;
    @Autowired
    private ConfigInfoDao configInfoDao;

    @Override
    public Envelope getConfigInfo() {
        try{
            return new Envelope(configInfoDao.getNewestConfig().getInfo());
        }catch (Exception e){
            e.printStackTrace();
            return Envelope.dbError;
        }
    }

    @Override
    public Envelope getRegions() {
        try {
            return new Envelope(instanceInfoDao.getAllRegion());
        }catch (Exception e){
            e.printStackTrace();
            return Envelope.dbError;
        }
    }

    @Override
    public Envelope getZoneByRegionId(String regionId) {
        try {
            return new Envelope(instanceInfoDao.getZoneByRegionId(regionId));
        }catch (Exception e){
            e.printStackTrace();
            return Envelope.dbError;
        }
    }

    @Override
    public Envelope getInstanceByZoneId(String zoneId) {
        try {
            return new Envelope(instanceInfoDao.getInstanceByZoneId(zoneId));
        }catch (Exception e){
            e.printStackTrace();
            return Envelope.dbError;
        }
    }
}
